@SqApi79
Feature: Providing test execution measures
  As a CXX Plugin user, I want to import the Google Test execution reports into SonarQube

  # |
  # | Specification:
  # | * The plugin is able to import test which conform to the schema
  # |   described in xunit.rnc Note: some test frameworks (QUnit,
  # |   AFAIK), skip the top-tag 'testsuites'. Those report are
  # |   compatible with the element testsuite of the schema and can be
  # |   imported too.
  # |
  # | * Additionally, the plugin is able to import every XML format
  # |   when given an XSLT-sheet, which performs the XSL to JUnit
  # |   conversion (see sonar.cxx.xslt.xxx)
  # |
  # | * To locate the test source file:
  # |   If either the testcase tag or the enclosing testsuite tag
  # |   contains the attribute 'filename', its content is assumed
  # |   to contain a path to the according test source file.
  # |   Filename in testcase overwrites filename in testsuite
  # |   if both are present.
  # |


  Scenario: Importing Google Test reports
    By default, the plugin doesn't try to assign the testcases
    found in the report to test files in Sonar, it just sums up
    all the measures and assigns it to the project. This makes the
    procedure more stable but doesn't provide the details for the
    testcases in SonarQube, i.e. the drilldown won't be possible.

    Given the project "googletest_project"
    When I run "sonar-scanner -X -Dsonar.cxx.xunit.reportPaths=gtest_without_fixture.xml"
    Then the analysis finishes successfully
    And the analysis in server has completed
    And the analysis log contains no error/warning messages except those matching:
      """
      .*WARN.*Unable to get a valid mac address, will use a dummy address
      .*WARN.*cannot find the sources for '#include <gtest/gtest\.h>'
      .*WARN.*cannot find the sources for '#include <unistd\.h>'
      """
    And the following metrics have following values:
      | metric               | value |
      | tests                | 1     |
      | test_failures        | 0     |
      | test_errors          | 0     |
      | skipped_tests        | 0     |
      | test_execution_time  | 0     |


  Scenario: Importing invalid Google Test report
    Given the project "googletest_project"
    When I run "sonar-scanner -Dsonar.cxx.errorRecoveryEnabled=false -Dsonar.cxx.xunit.reportPaths=invalid_report.xml"
    Then the analysis breaks
    And the analysis log contains a line matching:
      """
      .*ERROR: Invalid xUnit report, stop analysis.*
      """


  Scenario Outline: Importing augmented test reports generated by Google Test
    Test reports can be augmented with the filename-attribute which
    may help the plugin to assign the testcases in the report to the
    correct source code files.

    Given the project "googletest_project"
    When I run "sonar-scanner -X -Dsonar.cxx.xunit.reportPaths=<reportpaths>"
    Then the analysis finishes successfully
    And the analysis in server has completed
    And the analysis log contains no error/warning messages except those matching:
      """
      .*WARN.*Unable to get a valid mac address, will use a dummy address
      .*WARN.*cannot find the sources for '#include <gtest/gtest\.h>'
      .*WARN.*cannot find the sources for '#include <unistd\.h>'
      """
    And the following metrics have following values:
      | metric               | value |
      | tests                | 1     |
      | test_failures        | 0     |
      | test_errors          | 0     |
      | skipped_tests        | 0     |
      | test_execution_time  | 0     |
    Examples:
      | reportpaths              |
      | gtest_fname_in_ts.xml   |
      | gtest_fname_in_tc.xml   |
      | gtest_fname_in_both.xml |


  Scenario Outline: Google Test reports cannot be found or are empty
    Given the project "googletest_project"
    When I run "sonar-scanner -Dsonar.cxx.xunit.reportPaths=<reportpaths>"
    Then the analysis finishes successfully
    And the analysis in server has completed
    And the analysis log contains no error/warning messages except those matching:
      """
      .*WARN.*Unable to get a valid mac address, will use a dummy address
      .*WARN.*cannot find the sources for '#include <gtest/gtest\.h>'
      .*WARN.*cannot find the sources for '#include <unistd\.h>'
      .*WARN.*The report.*seems to be empty, ignoring\.
      .*WARN.*Cannot find a report for '.*'
      """
    And the following metrics have following values:
      | metric               | value |
      | tests                | None  |
      | test_failures        | None  |
      | test_errors          | None  |
      | skipped_tests        | None  |
      | test_execution_time  | None  |
    Examples:
      | reportpaths       |
      | notexistingpath  |
      | empty_report.xml |
